package com.imist.mybatisdemo2.listener;

import com.imist.mybatisdemo2.utils.SqlSessionFactoryUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class InitSqlSessionListener implements ServletContextListener {
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("容器加载中....");
        //初始化我们的sqlseeionfactory对象
        SqlSessionFactoryUtils.initSqlsessionFactory();
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        //关闭SQLSession对象
        System.out.println("容器销毁中....");
        SqlSessionFactoryUtils.closed();
    }
}
